package com.nage.components.collision;

import com.nage.components.movement.Vector2D;
import com.nage.engine.GameObject;

public class PongBat extends Collidable {

	private static final byte ERROR = (byte) 0xFF;
	private static final byte LEFT_1 = (byte) 0x01;
	private static final byte LEFT_2 = (byte) 0x02;
	private static final byte CENTER = (byte) 0x03;
	private static final byte RIGHT_2 = (byte) 0x04;
	private static final byte RIGHT_1 = (byte) 0x05;
	private byte hit_area;

	public PongBat(GameObject obj) {
		super(obj);
	}
	 
	@Override
	public void onCollision(Collision c) {
		Vector2D point = c.getCollisionPoint();
		float offset = point.x - parent.x;
		float section = shape.width / 5;
		if(offset < 0) {
			hit_area = ERROR;
		} else if(offset < section) {
			hit_area = LEFT_1;
		} else if (offset < section * 2) {
			hit_area = LEFT_2;
		} else if (offset < section * 3) {
			hit_area = CENTER;
		} else if (offset < section * 4) {
			hit_area = RIGHT_2;
		} else if (offset < section * 5) {
			hit_area = RIGHT_1;
		} else {
			hit_area = ERROR;
		}
		return;
	}

	public float getXModifier() {
		float mod = 0;
		switch(hit_area) {
		case LEFT_1:
			mod = -0.2f;
			break;
		case LEFT_2:
			mod = -0.1f;
			break;
		case CENTER:
			mod = 0.0f;
			break;
		case RIGHT_2:
			mod = 0.1f;
			break;
		case RIGHT_1:
			mod = 0.2f;
			break;
		}
		hit_area = ERROR;
		return mod;
	}

}
